package com.uk.ui.windows;

import com.uk.data.containers.FaturaContainer;
import com.uk.data.ejbs.IFaturaBean;
import com.uk.data.entities.Fatura;
import com.uk.data.entities.Kontrata;
import com.uk.data.entities.Tarifa;
import com.uk.interfaces.PopupWindowListener;
import com.uk.myclasses.ATable;
import com.uk.ui.PopupWindow;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Table;

public class FaturaSelectWindow extends PopupWindow implements ValueChangeListener{
	private PopupWindowListener listener;
	private FaturaContainer faturaContainer;
	private Fatura selectedFatura;
	private IFaturaBean faturaBean;
	
	public FaturaSelectWindow(PopupWindowListener listener , IFaturaBean faturaBean) {
		
		super("Lista e faturave", "400px", "200px");
		this.center();
		this.listener = listener;
		this.faturaBean = faturaBean;
	}

	
	public void setKontrata(Kontrata kontrata){
		this.removeAllComponents();
		this.faturaContainer = FaturaContainer.createFromEjb(faturaBean, kontrata, 5);
		
		ATable table = new ATable();
		table.setContainerDataSource(this.faturaContainer);
		table.setVisibleColumns(new Object[]{"id","dataLeximAktual","leximiAktual"});
		table.setColumnHeaders(new String[]{"ID","Data","Leximi"});
		
		table.setPageLength(5);
		table.setSelectable(true);
		table.setImmediate(true);
		table.setSortDisabled(true);
		table.setWidth("350px");
		table.setSelectable(true);
		table.setImmediate(true);
		table.addListener(this);
		this.addComponent(table);
		this.setPositionX(300);
		this.setPositionY(100);
		table.setDescription("Klikoni ne rreshtin e tabeles qe doni te zgjidhni");
	}
	
	
	@Override
	public void valueChange(ValueChangeEvent event) {
		this.selectedFatura = (Fatura) event.getProperty().getValue();
		this.listener.returnAction(this);
		this.close();
		
	}


	public Fatura getSelectedFatura() {
		return selectedFatura;
	}


}
